home *** CD-ROM | disk | FTP | other *** search
/ Resource for Source: C/C++ / Resource for Source - C-C++.iso / misc_src / sqlsomdb / sample42 / logon.frm < prev    next >
Text File  |  1995-11-01  |  5KB  |  190 lines

  1. VERSION 2.00
  2. Begin Form logon 
  3.    BackColor       =   &H00C0FFC0&
  4.    Caption         =   "Logon For SQL Server 4.2x"
  5.    ClientHeight    =   1665
  6.    ClientLeft      =   1665
  7.    ClientTop       =   3285
  8.    ClientWidth     =   5580
  9.    ControlBox      =   0   'False
  10.    Height          =   2070
  11.    Left            =   1605
  12.    LinkTopic       =   "Form2"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   1665
  16.    ScaleWidth      =   5580
  17.    Top             =   2940
  18.    Width           =   5700
  19.    Begin CommandButton cancelbut 
  20.       Cancel          =   -1  'True
  21.       Caption         =   "Cancel"
  22.       Height          =   615
  23.       Left            =   3600
  24.       TabIndex        =   9
  25.       Top             =   840
  26.       Width           =   1695
  27.    End
  28.    Begin CommandButton logonbut 
  29.       Caption         =   "Logon to Server"
  30.       Default         =   -1  'True
  31.       Height          =   615
  32.       Left            =   3600
  33.       TabIndex        =   8
  34.       Top             =   120
  35.       Width           =   1695
  36.    End
  37.    Begin TextBox dbase 
  38.       Height          =   285
  39.       Left            =   1440
  40.       TabIndex        =   7
  41.       Text            =   "pubs"
  42.       Top             =   1200
  43.       Width           =   1935
  44.    End
  45.    Begin TextBox serverid 
  46.       Height          =   285
  47.       Left            =   1440
  48.       TabIndex        =   6
  49.       Text            =   "42NT"
  50.       Top             =   840
  51.       Width           =   1935
  52.    End
  53.    Begin TextBox password 
  54.       Height          =   285
  55.       Left            =   1440
  56.       TabIndex        =   5
  57.       Top             =   480
  58.       Width           =   1935
  59.    End
  60.    Begin TextBox uid 
  61.       Height          =   285
  62.       Left            =   1440
  63.       TabIndex        =   4
  64.       Text            =   "sa"
  65.       Top             =   120
  66.       Width           =   1935
  67.    End
  68.    Begin Label Label4 
  69.       Alignment       =   1  'Right Justify
  70.       Caption         =   "DataBase :"
  71.       Height          =   195
  72.       Left            =   200
  73.       TabIndex        =   3
  74.       Top             =   1200
  75.       Width           =   1000
  76.    End
  77.    Begin Label Label3 
  78.       Alignment       =   1  'Right Justify
  79.       Caption         =   "Server Id :"
  80.       Height          =   195
  81.       Left            =   200
  82.       TabIndex        =   2
  83.       Top             =   840
  84.       Width           =   1000
  85.    End
  86.    Begin Label Label2 
  87.       Alignment       =   1  'Right Justify
  88.       Caption         =   "PassWord :"
  89.       Height          =   195
  90.       Left            =   200
  91.       TabIndex        =   1
  92.       Top             =   480
  93.       Width           =   1000
  94.    End
  95.    Begin Label Label1 
  96.       Alignment       =   1  'Right Justify
  97.       Caption         =   "User Id :"
  98.       Height          =   195
  99.       Left            =   200
  100.       TabIndex        =   0
  101.       Top             =   120
  102.       Width           =   1000
  103.    End
  104. End
  105.  
  106. Sub cancelbut_Click ()
  107.  
  108. '   User does not wish to connect
  109.  
  110.     Unload Me
  111. End Sub
  112.  
  113. Sub logonbut_Click ()
  114. '   If the application has not already initialized the
  115. '   DB-Library then use the SqlInit function to init
  116. '   the DB-Library
  117.  
  118.     If dblib = "" Then
  119.         dblib = SqlInit()
  120.     End If
  121.  
  122. '   This form solicits from the user the following
  123. '   information
  124. '
  125. '   Userid
  126. '   Password
  127. '   Database to be used -   this should be either pubs
  128. '                           or pubs2 for this application
  129. '                           to function property
  130.  
  131.     usid = uid.Text
  132.     If usid = "" Then
  133.         MsgBox "You must enter a userid"
  134.         Exit Sub
  135.     End If
  136.     
  137.     pword = password.Text
  138.     sid = serverid.Text
  139.     If sid = "" Then
  140.         MsgBox "You must enter the server name"
  141.         Exit Sub
  142.     End If
  143.  
  144.     datbase = dbase.Text
  145.     If datbase = "" Then
  146.         MsgBox "You must enter the database name - pubs for SqlServer 4.2 or pubs2 for System 10"
  147.         Exit Sub
  148.     End If
  149.  
  150.     If datbase <> "pubs" Then
  151.         MsgBox "Your database name should be - pubs for SqlServer 4.2"
  152.     End If
  153.  
  154.     
  155. '   Once the information needed to open a connection is
  156. '   obtained from the user open a connection with the server
  157. '   using the SqlOpenConnection function. This function
  158. '   returns a connection pointer if the connection is made.
  159. '   if no connection is made then the connection pointer will
  160. '   be zero (NULL)
  161.  
  162.     dbconn = SqlOpenConnection(sid, usid, pword, "", "SombreroApp1")
  163.     
  164. '   If the connection is made the next thing we need to do
  165. '   is point to the correct database which has the data
  166. '   required for the application. In this case the data is
  167. '   in the authors table found in the pubs database for SQL
  168. '   Server 4.2 or in the pubs2 database for SYBASE System 10
  169.  
  170.     If dbconn <> 0 Then
  171.         ret = SqlUse(dbconn, datbase)
  172.         If ret <> 1 Then
  173.             SqlClose (dbconn)
  174.             dbconn = 0
  175.         End If
  176.     Else
  177.         Exit Sub
  178.     End If
  179.  
  180. '   If the connection has been made and the database changed
  181. '   to pubs/pubs2 then hiding the connect button will allow
  182. '   the application to run
  183.  
  184.     If ret = 1 Then
  185.         mainform!multibut.Visible = False
  186.         Unload Me
  187.     End If
  188. End Sub
  189.  
  190.